home *** CD-ROM | disk | FTP | other *** search
- /*
- * FednetCmp - Fednet file compression/decompression
- * Iconbar icon
- * Copyright (C) 2001 Chris Bazley
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public Licence as published by
- * the Free Software Foundation; either version 2 of the Licence, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public Licence for more details.
- *
- * You should have received a copy of the GNU General Public Licence
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- /* ANSI library files */
- #include <stdlib.h>
- #include <stdbool.h>
- #include <string.h>
- #ifdef DEBUG
- #include <stdio.h>
- #endif
-
- /* RISC OS library files */
- #include "kernel.h"
- #include "toolbox.h"
- #include "event.h"
- #include "iconbar.h"
- #ifdef DEBUG
- #include "flex.h"
- #endif
-
- /* My library files */
- #include "err.h"
- #include "msgtrans.h"
- #include "Macros.h"
- #include "Loader.h"
- #include "ViewsMenu.h"
- #include "hourglass.h"
-
- /* Local headers */
- #include "Main.h"
- #include "Utils.h"
- #include "SaveFile.h"
- #include "SaveDir.h"
- #include "FNCIconbar.h"
-
- static ObjectId Iconbar_id = NULL_ObjectId;
-
- /* ----------------------------------------------------------------------- */
- /* Function prototypes */
-
- static ToolboxEventHandler _Iconbar_clickhandler;
- static LoaderFinishedHandler _Iconbar_filedrophandler, _Iconbar_dirdrophandler;
-
- /* ----------------------------------------------------------------------- */
- /* Public functions */
-
- void Iconbar_initialise(ObjectId id)
- {
- Iconbar_id = id;
-
- /* Register listeners for files dropped on iconbar icon */
- EF(loader_register_listener(0, FILETYPE_ALL, id, NULL, load_plain, _Iconbar_filedrophandler, (void *)1));
- for(int i = 0; i < sizeof(fednet_filetypes)/sizeof(int); i++) {
- EF(loader_register_listener(0, fednet_filetypes[i], id, NULL, load_compressed, _Iconbar_filedrophandler, (void *)0));
- }
- EF(loader_register_listener(LISTENER_FILEONLY, FILETYPE_DIR, id, NULL, NULL, _Iconbar_dirdrophandler, NULL));
- EF(loader_register_listener(LISTENER_FILEONLY, FILETYPE_APP, id, NULL, NULL, _Iconbar_dirdrophandler, NULL));
-
- /* Listen for mouse clicks */
- EF(event_register_toolbox_handler(id, Iconbar_Clicked, _Iconbar_clickhandler, NULL));
- }
-
- /* ----------------------------------------------------------------------- */
- /* Private functions */
-
- static int _Iconbar_clickhandler(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
- {
- #ifdef DEBUG
- int keypressed = _kernel_osbyte(129, (0^0xff), 0xff);
- /* Check whether SHIFT held */
- if(keypressed == _kernel_ERROR) {
- _kernel_oserror *err = _kernel_last_oserror();
- err_complain(err->errnum, err->errmess);
- return 1;
- }
- if((keypressed & 0xff) == 0xff) {
- char string[255];
- int prev = flex_set_budge(1);
- sprintf(string, "report Budge state = %d", prev);
- flex_set_budge(prev);
- _kernel_oscli(string);
- }
- else
- #endif
- /* bring all open windows to front */
- RE(ViewsMenu_showall())
-
- return 1; /* claim event */
- }
-
- /* ----------------------------------------------------------------------- */
-
- static void _Iconbar_filedrophandler(char *file_path, bool data_saved, flex_ptr buffer, int filetype, void *handle)
- {
- /* setting of 'handle' indicates compress(1) or decompress(0) file */
- ObjectId oldbox, newbox;
-
- /* Check for existing dialogues */
- if(!multi_saveboxes)
- oldbox = last_savebox;
- else {
- if(data_saved)
- oldbox = ViewsMenu_findview(file_path);
- else
- oldbox = NULL_ObjectId;
- }
-
- /* Create save dialogue */
- newbox = SaveFile_create(file_path, data_saved, buffer, (int)handle);
- if(newbox == NULL_ObjectId) {
- flex_free(buffer);
- return;
- }
-
- /* Open save dialogue */
- if(E(open_above_iconbar(0, newbox, Iconbar_id, NULL_ComponentId))) {
- /* Oh dear, new dialogue window won't open */
- RE(toolbox_delete_object(0, newbox))
- }
- else {
- last_savebox = newbox;
- /* Remove any old savebox (same filepath or only one at a time allowed) */
- if(oldbox != NULL_ObjectId)
- RE(toolbox_hide_object(0, oldbox)) /* will delete self when ready */
- }
- }
-
- /* ----------------------------------------------------------------------- */
-
- static void _Iconbar_dirdrophandler(char *file_path, bool data_saved, flex_ptr buffer, int filetype, void *handle)
- {
- ObjectId oldbox, newbox;
-
- /* Check for existing dialogues */
- if(!multi_saveboxes)
- oldbox = last_savebox;
- else {
- if(data_saved)
- oldbox = ViewsMenu_findview(file_path);
- else
- oldbox = NULL_ObjectId;
- }
-
- /* Create an output dialogue for a new batch operation */
- newbox = SaveDir_create(file_path);
- if(newbox == NULL_ObjectId)
- return;
-
- /* Open save dialogue */
- if(E(open_above_iconbar(0, newbox, Iconbar_id, NULL_ComponentId))) {
- /* Oh dear, new dialogue window won't open */
- RE(toolbox_delete_object(0, newbox))
- }
- else {
- last_savebox = newbox;
- /* Remove any old savebox (same filepath or only one at a time allowed) */
- if(oldbox != NULL_ObjectId)
- RE(toolbox_hide_object(0, oldbox)) /* will delete self when ready */
- }
- }
-